/**
 * @file   config.cpp
 * @author wolfhead <wolfhead@wolfhead-laptop>
 * @date   Tue Oct 25 11:06:58 2011
 * 
 * @brief  
 * 
 * 
 */
#include "config.h"
#include <sstream>
#include <acapella/string/string_util.hpp>


using namespace PP;

//////////////////////////////////////////////////////////////////////
// AttributeConfig
AttributeConfig::AttributeConfig()
    : isKey(false)
{
}

std::string AttributeConfig::ToString() const
{
    std::ostringstream oss;
    oss << "name:" << name << ","
        << "type:" << type << ","
        << "length:" << length << ","
        << "defaultValue:" << defaultValue << ","
        << "isKey:" << isKey;
    return oss.str();
}

std::string AttributeConfig::ToJson() const
{
    using namespace acapella;

    std::ostringstream oss;

    oss << "{"
        << StringUtil::Quote("name") << ":" << StringUtil::Quote(name) << ","
        << StringUtil::Quote("type") << ":" << StringUtil::Quote(type) << ","
        << StringUtil::Quote("length") << ":" << length << ","
        << StringUtil::Quote("defaultValue") << ":" << StringUtil::Quote(defaultValue) << ","
        << StringUtil::Quote("isKey") << ":" << isKey 
        << "}";

    return oss.str();
}


//////////////////////////////////////////////////////////////////////
// DictionaryConfig

std::string DictionaryConfig::ToString() const
{
    std::ostringstream oss;
    oss << "id:" << id << ","
        << "name:" << name << ","
        << "parentName" << parentName;
    return oss.str();
}

std::string DictionaryConfig::ToJson() const
{
    using namespace acapella;
    
    std::ostringstream oss;
    oss << "{" 
        << StringUtil::Quote("id") << ":" << id << ","
        << StringUtil::Quote("name") << ":" << StringUtil::Quote(name) << ","
        << StringUtil::Quote("parentName") << ":" << StringUtil::Quote(parentName) << ","
        << StringUtil::Quote("attributes") << ":[";

    bool firstAttr = true;
    for (std::vector<AttributeConfig>::const_iterator it = attributes.begin();
         it != attributes.end();
         ++it)
    {
        if (!firstAttr)
        {
            oss << ",";
        }

        oss << it->ToString();
        firstAttr = false;
    }
    
    oss << "]}";

    return oss.str();
}
